package com.qf.springmq.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.databind.JsonSerializer;

import com.qf.springmq.mapper.VoteMapper;
import com.qf.vote2203.dbvote.entity.Vote;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Author liujinchi
 * @Date 2023/3/2 14:53
 * @注释
 */
@Component
public class WriteDB {

    @Autowired
    VoteMapper voteMapper;

    @RabbitListener(queues = "*.votequeue.*")
    public void readDB(List<Vote>  list){

       //ArrayList<Vote> votes = new ArrayList<>();
       //list.stream().forEach(json -> {
       //   Vote user = JSON.toJavaObject(json,Vote.class);
       //   votes.add(user);
       //});
      voteMapper.insertByList(list);

    }
}
